package cn.edu.neusoft.maxingxin231.yuejian06.Fragment.activityFragment;

import android.content.Context;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import java.util.List;

import cn.edu.neusoft.maxingxin231.yuejian06.Adapter.MasterAdapter;
import cn.edu.neusoft.maxingxin231.yuejian06.Adapter.RookieAdapter;
import cn.edu.neusoft.maxingxin231.yuejian06.Bean.MasterBean;
import cn.edu.neusoft.maxingxin231.yuejian06.Bean.TrainBean;
import cn.edu.neusoft.maxingxin231.yuejian06.Listener.ListListener;
import cn.edu.neusoft.maxingxin231.yuejian06.Model.MasterModel;
import cn.edu.neusoft.maxingxin231.yuejian06.Model.RookieModel;
import cn.edu.neusoft.maxingxin231.yuejian06.R;

public class MasterFragment extends Fragment {
    private View view=null;
    private Context context;
    private RecyclerView recycleview_master;
    private RecyclerView.LayoutManager layoutManager;
    private MasterAdapter masterAdapter;
    private List<MasterBean> items=null;
    ListListener<MasterBean> masterBeanListListener=new ListListener<MasterBean>() {
        @Override
        public void onResponse(List<MasterBean> list) {
            Toast.makeText(context, "success", Toast.LENGTH_SHORT).show();
            items = list;
            masterAdapter.setList(list);
        }

        @Override
        public void onFail(String msg) {
            Toast.makeText(context,"fail:"+msg,Toast.LENGTH_SHORT).show();
        }
    };

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        context=getActivity();
        // Inflate the layout for this fragment
        view=inflater.inflate(R.layout.fragment_master, container, false);
        recycleview_master=(RecyclerView) view.findViewById(R.id.recycle_master);
        layoutManager=new LinearLayoutManager(context);
        recycleview_master.setLayoutManager(layoutManager);
        masterAdapter=new MasterAdapter(getActivity(),items,R.layout.club_card);
        masterAdapter.setList(items);

        recycleview_master.setAdapter(masterAdapter);
        MasterModel masterModel = new MasterModel();
        masterModel.getMasterList(masterBeanListListener);
        return view;
    }
    public interface OnFragmentInteractionListener {
        // TODO: Update argument type and name
        void onFragmentInteraction(Uri uri);
    }
}
